//
//  PackageDetailStoreInfoCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/8/2.
//  Copyright © 2020 王洋. All rights reserved.
//
#import "HorizontalCollectionView.h"

#import "PackageDetailStoreInfoCell.h"

@interface PackageDetailStoreInfoCell ()

@property (nonatomic, strong) HorizontalCollectionView *promiseCollectionView;

@end

@implementation PackageDetailStoreInfoCell

+ (CGFloat)calculateHeightWithModel:(PackageDetailModule *)model {
//    if (model.sellerModel.admId == 13) {
    CGFloat top = 10;
    CGFloat storeHeight = 95;
    CGFloat addressHeight = 30;
    CGFloat wyxHeight = 45;
    
    if (model.sellerModel.examStatus == 2) {
        wyxHeight = 45;
    } else {
        wyxHeight = CGFLOAT_MIN;
    }
    return top + storeHeight + addressHeight + wyxHeight;
}

- (void)awakeFromNib {
    [super awakeFromNib];

    [self.wuyouxuanControl addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
        if (self.PackageDetailStoreInfoCellBlock) {
            self.PackageDetailStoreInfoCellBlock();
        }
    }];
    
    [self.promiseBGView addSubview:self.promiseCollectionView];
    [self.promiseCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_equalTo(0);
    }];

}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self.storeIcon pp_clipCorners:UIRectCornerAllCorners radius:6];
    });
}

- (void)fillCellWithModel:(PackageDetailModule *)model {
    
    [self.promiseCollectionView fillPromiseData:model.SellerPromiseLabelAuthernticationList];

    NSString *url = [TT_OSSManager reSourceUrl:model.sellerModel.logoUrl type:BA_resizeType_plus];
    [self.storeIcon sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.storeNameLab.text = model.sellerModel.sellerName;
    
    //self.numLab.text = [NSString stringWithFormat:@"%ld套餐 %lu条 %ld关注 %.1f分",(long)model.sellerModel.goodsCount,(unsigned long)model.sellerModel.sellerCount,(long)model.sellerModel.collectionCount,model.sellerModel.sellerEvaluateStar];
    self.numLab.text = [NSString stringWithFormat:@"%ld套餐",(long)model.sellerModel.goodsCount];
    if (model.sellerModel.distance > 0) {
        if (model.sellerModel.distance < 1000) {
            self.addressLab.text = [NSString stringWithFormat:@"%.fm | %@",model.sellerModel.distance,model.sellerModel.sellerAddress]; ;
        } else {
            self.addressLab.text = [NSString stringWithFormat:@"%.fkm | %@",model.sellerModel.distance/1000,model.sellerModel.sellerAddress]; ;
        }
    } else {
        self.addressLab.text = model.sellerModel.sellerAddress;
    }
    
    
//    if (model.sellerModel.admId == 13) {
    self.wyxIcon1.hidden = YES;
    self.wyxLab1.hidden = YES;
    self.wyxIcon2.hidden = YES;
    self.wyxLab2.hidden = YES;
    self.wyxIcon3.hidden = YES;
    self.wyxLab3.hidden = YES;
    
    if (model.sellerModel.examStatus == 2) {

        self.wuyouxuanControl.hidden = NO;
        self.WYXIcon.hidden = NO;
        
        for (int i = 0; i < model.sysWorryFreeLabel.count; i++) {
            if (i == 0) {
                self.wyxIcon1.hidden = NO;
                self.wyxLab1.hidden = NO;
                self.wyxLab1.text = model.sysWorryFreeLabel[i].labelName;
            }
            if (i == 1) {
                self.wyxIcon2.hidden = NO;
                self.wyxLab2.hidden = NO;
                self.wyxLab2.text = model.sysWorryFreeLabel[i].labelName;
            }
            if (i == 2) {
                self.wyxIcon3.hidden = NO;
                self.wyxLab3.hidden = NO;
                self.wyxLab3.text = model.sysWorryFreeLabel[i].labelName;
            }
        }
        
    } else {
        self.wuyouxuanControl.hidden = YES;
        self.WYXIcon.hidden = YES;

    }
    
}

- (HorizontalCollectionView *)promiseCollectionView {
    if (!_promiseCollectionView) {
        _promiseCollectionView = [[HorizontalCollectionView alloc] initWithType:HorizontalCollectionType_packageDetail];
    }
    return _promiseCollectionView;
}

@end
